'''
Created on Sep 5, 2011

@author: koos
'''
from flask import Flask, request, session, flash, redirect, url_for, render_template
from config import Conf
import database

app = Flask(__name__)
app.config.from_object(Conf)

@app.route("/login", methods=["GET", "POST"])
def login():
    error = None
    if request.method == "POST":
        sql = database.db
        sql = sql.session.query(database.User).filter(database.User(request.form["username"]))
        if request.form["username"] != sql.username:
            error = "Invalid User"
        elif request.form["password"] != sql.password:
            error = "Invalid pasword"
        else:
            session["logged_in"]
            flash("Thou has been logged in")
            return redirect(url_for("front"))
    return render_template("login.html", error = error)
         

@app.route("/")
def front():
    return "Logged in"


if __name__ == "__main__":
    app.run()